Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static_file.name and .basename Liquid attributes #5264

Merged
merged 4 commits into from Sep 29, 2016
Merged

Add static_file.name and .basename Liquid attributes #5264

merged 4 commits into from Sep 29, 2016

Conversation

DirtyF
Copy link
Member

@DirtyF DirtyF commented Aug 20, 2016

Disclaimer: These are my first ruby lines 馃槄

A proposal to fix #5263

@@ -97,6 +97,7 @@ def write(dest)

def to_liquid
{
"filename" => File.basename(name, extname),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or simply use name in order to simple call file.name in liquid?

@@ -1,6 +1,6 @@
module Jekyll
class StaticFile
attr_reader :relative_path, :extname
attr_reader :relative_path, :extname, :name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a short way of defining:

def name
  @name
end

Therefore, the best thing to do here is to set @name in the initialize method using the code you have on line 100 and then, when you are constructing to_liquid below, you can just call the name method instead of re-calculating its value. Does that make sense?

Copy link
Member Author

@DirtyF DirtyF Aug 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parkr yes, but then it breaks the tests as name used to be the whole name of the file including the extension. 馃槙

@parkr
Copy link
Member

parkr commented Aug 22, 2016

Well done, @DirtyF! This is great. I left a comment above which should help you get this ready for a merge. 馃槃 And well done adding a test! I would love to also see a test for the name attr_reader you added, too, just to make sure it keeps working as we expect.

馃帀

@parkr parkr added this to the 3.2.2 milestone Aug 22, 2016
@envygeeks
Copy link
Contributor

I'm not against this but the LGTM is being witheld since this is a breaking change and there is no backwards compatibility being kept until 4.0, can somebody explain to me what the ramifications of this change are?

@DirtyF
Copy link
Member Author

DirtyF commented Aug 23, 2016

@envygeeks I didn't intend a breaking change, only wanted to add an extra Liquid shortcut to access the name of a static file without having to use liquid filters to remove the extra parts.

@envygeeks
Copy link
Contributor

@DirtyF Well, the question really is, can I still access it the old way if I want to?

@parkr
Copy link
Member

parkr commented Aug 24, 2016

/cc @jekyll/stability

@parkr parkr assigned ghost Aug 24, 2016
@@ -97,6 +97,7 @@ def write(dest)

def to_liquid
{
"name" => File.basename(name, extname),
Copy link
Member

@parkr parkr Aug 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with adding this to Liquid. When you do static_file.name in Ruby, it expects something else, though?

Copy link
Member Author

@DirtyF DirtyF Aug 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand, in the initialize function, name is the complete name of the file including the extension.

I just modified the output in Liquid, to be able to get only the name without the extension, already available as extname. I did not want to modify the current behavior, as it would break all current tests.

As a total beginner, I have no clue how to properly achieve this. I just thought that we got to keep name as it is, and just add filename in the to_liquid function to be able to use both.

@ghost
Copy link

ghost commented Aug 26, 2016

@envygeeks what do you mean 'the old way'? all i see in this change is additions, nothing breaking

@parkr
Copy link
Member

parkr commented Aug 26, 2016

Interesting, this change LGTM. I think the main issue was the possibility that StaticFile#name (in Ruby) would be changed if he implemented my suggestion.

@DirtyF, would you please leave a comment next to your addition to to_liquid explaining, essentially, that the value is to match the name value in Page?

@DirtyF
Copy link
Member Author

DirtyF commented Aug 27, 2016

@parkr I don't get what you mean 馃槙

  • {{ page.name }} returns about.md
  • {{ file.name }} would return static_file not static_file.txt (cf. use case in Get static file name聽#5263)

So it doesn't match Page, and that is a concern. Open to suggestions here (naming things is hard). I can revert 326332a

I completed the documentation with explicit examples for liquid metadata available for static files.

@ghost
Copy link

ghost commented Aug 27, 2016

@DirtyF I'd suggest naming it basename (and providing the name property as well).

Other, unrelated note: would we see an improvement using Jekyll Drops for these things?

@DirtyF
Copy link
Member Author

DirtyF commented Aug 27, 2016

@spudowiar you're right basename is far less confusing and more explicit.

Documentation updated to reflect the changes.

docs-static-files

@envygeeks
Copy link
Contributor

LGTM. /cc @jekyll/core

@parkr parkr modified the milestones: 3.2.2, 3.3 Sep 22, 2016
Copy link
Member

@parkr parkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DirtyF Remind me: is this consistent with page.name for Pages and Documents?

@DirtyF
Copy link
Member Author

DirtyF commented Sep 23, 2016

@parkr yes it is.

@parkr parkr changed the title Get static filename Add static_file.name and .basename Liquid attributes Sep 29, 2016
@parkr
Copy link
Member

parkr commented Sep 29, 2016

This should eventually become a Drop. For now, LGTM.

@jekyllbot: merge +minor

@jekyllbot jekyllbot merged commit ef3f9d0 into jekyll:master Sep 29, 2016
jekyllbot added a commit that referenced this pull request Sep 29, 2016
@DirtyF DirtyF deleted the static-file-name branch October 1, 2016 23:56
@jekyll jekyll locked and limited conversation to collaborators Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get static file name
4 participants